import { login } from "@/api/user";
import { getToken, setToken, removeToken } from "@/utils/auth";
export default {
  namespaced: true,
  state: {
    token: getToken() || "",
  },
  mutations: {
    setToken(state, token) {
      // 存入vuex
      state.token = token;
      // 存入cookie
      setToken(token);
    },
  },
  actions: {
    async fetchLogin(ctx, data) {
      const token = await login(data);
      ctx.commit("setToken", token);
    },
  },
};
